/**
 * 封装数字的输入框，主要为了解决键盘的不退出的问题
 */
var React = require('react-native');
var {
  View,
  TextInput,
  TouchableOpacity,
  Platform,
} = React;


var noop = () => {};


var NumberInput = React.createClass({
  getDefaultProps(){
    return {
      value: '0',
      onBlur: noop,
      onFocus: noop,
      onChangeText: noop
    };
  },


  getInitialState(){
    //默认不可编辑
    return {
      editable: false
    };
  },



  render() {
    return (
      <TouchableOpacity onPress={this._handlePress}>
        <TextInput
          ref='numInput'
          value={this.props.value}
          onBlur={this._handleBlur}
          textAlign='center'
          keyboardType='numeric'
          onChangeText={this.props.onChangeText}
          onFocus={this._hanldFocus}
          style={this.props.style}/>
      </TouchableOpacity>
    );
  },


  // _handlePress(){
  //   this.setState({
  //     editable: true
  //   }, () => {
  //     this.refs.numInput.focus();
  //   });
  // },

  _hanldFocus(){
    this.refs.numInput.focus();
    this.props.onFocus();
  },

  _handleBlur(){
   this.setState({
     editable: false
   });

   this.props.onBlur();
  }
});


module.exports = NumberInput;
